﻿using Demo;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class HomeController : ControllerBase
    {

        private readonly MyDbContext _service;
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger,MyDbContext service)
        {
            _logger = logger;
            _service = service;
        }

        [HttpGet]
        public string Get()
        {
            try
            {
                var u = new Demo.Models.User
                {
                    UserName = DateTime.Now.ToString(),
                     Property=new List<Demo.Models.UserProperty> { 
                        new Demo.Models.UserProperty{ Key=Guid.NewGuid().ToString(), Value=Guid.NewGuid().ToString() },
                        new Demo.Models.UserProperty{ Key=Guid.NewGuid().ToString(), Value=Guid.NewGuid().ToString() }

                     }


                };
                try
                {
                    _service.Users.Add(u);
                    _service.SaveChanges();

                    var d = _service.Users
                        .Include(x => x.Property)
                        .ToList();
                }
                catch (Exception ex)
                {

                    throw;
                }
               
              
            }
            catch (Exception ex)
            {

                throw;
            }
          

            return DateTime.Now.ToString();
        }
    }
}
